/**
 * 此方法似乎适合所有字符串查询
 * @param {string} sourceString 
 * @param {string} search 
 * @returns bool
 */
function match(sourceString, search)
{

    let foundIndex = 0;

    const searchArr = Array.from(search);

    // 我这个算是状态机器吗????
    function checkChar(char, index){
        if(char === searchArr[index]){
            return ++index;
        }else{
            let nowIndex = 0;
            if((index -1) < 0 ){
                nowIndex = 0;
            }else{
                nowIndex = index - 1;
            }
            if(nowIndex != index){
                return checkChar(char, nowIndex);
            }else{
                return nowIndex;
            }
        }
    }

    for(let i=0; i<sourceString.length; i++)
    {
        foundIndex = checkChar(sourceString.charAt(i), foundIndex);
        if(foundIndex >= searchArr.length){
            return true;
        }
    }

    return false;

}


let searchResult = match('bcaabababxxfgya', 'abababx');
console.log(searchResult);